<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb :separator-icon="ArrowRight">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片区域 -->
    <el-card >
      <!-- 用户列表区域 -->
      <el-table :data="rightsList" style="width: 100%" border stripe ref="table"  :height="tableHeight">
        <el-table-column type="index" label="#" />
        <el-table-column prop="authName" label="权限名称"  />
        <el-table-column prop="path" label="路径"  />
        <el-table-column prop="level" label="权限等级"  >
          <template  #default="scope">
            <el-tag v-if="scope.row.level==='0'">一级</el-tag>
            <el-tag type="success" v-if="scope.row.level==='1'">二级</el-tag>
            <el-tag type="warning" v-if="scope.row.level==='2'">三级</el-tag>
          </template>
        </el-table-column>
      </el-table> 
        
    </el-card>

  </div>
</template>

<script>
export default {
  data(){
    return{
      tableHeight: 450,
      //权限列表
      rightsList:[],
    }
  },
  
  //固定表头，表的高度自适应
  //通过延迟方法来设置值
  mounted:function(){
    setTimeout(() => {
      //this.$refs.table.$el.offsetTop：表格距离浏览器的高度
      his.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop;
    },100)
   },

  created(){
    //获取所有权限
    this.getRightsList()
  },

  methods:{
    //获取权限列表
    async getRightsList(){
      const {data:res} =await this.$http.get('/my/rights/list')
      if(res.meta.status!==200) {
        return this.$message.err('获取权限列表失败')
      }
      this.rightsList=res.data
      //console.log(this.rightsList)

    }

  }


}
</script>

<style lang="less" scoped>

</style>